Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Copying the messages and marking a message in between as unread generates 'new' in the text #18228

Conversation

Victor-Nyagudi
Copy link
Contributor

@Victor-Nyagudi Victor-Nyagudi commented May 1, 2023

Details

Added the styles.userSelectNone style to UnreadActionIndicator so users are visually aware it's not copied to the clipboard and then removed all elements with this style applied from the copied contents inside SelectionScraper.

This way, anything that's given a style of user-select: none is omitted from the clipboard whenever the user copies something.

Fixed Issues

$ #17838
$ #17838 (comment)

Tests

  1. Log in with an account that has at least one chat created on Mac Chrome/Mac Safari/Mac Desktop
  2. Click on any chat
  3. Send multiple messages e.g. 1, 2, 3, 4, 5, 6
  4. Select a message in between e.g. 4 and mark it as unread (make sure a green line appears after marking as unread, otherwise, try refreshing the page and mark as unread again)
  5. Copy all the messages i.e. left-click and drag over all the messages then copy (Cmd/Ctrl + C)
  6. Verify the word New that's to the right of the green line is not highlighted
  7. Paste the selection in the composer i.e. Cmd/Ctrl + V
  8. Verify the word New is not part of pasted content
  9. Click on a separate chat and then come back to the one with unread message to update its status to read
  10. Copy and paste all the messages into the composer like before
  11. Verify that pasted content is the same as what's copied i.e. works as usual
  • Verify that no errors appear in the JS console

Offline tests

Same as above but go offline after logging in i.e. step 1 (or force offline in staging).

QA Steps

Same as Tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
expensify-mac-chrome-paste-without-new-word.mov
expensify-mac-safari-paste-without-new-word.mov
Mobile Web - Chrome

expensify-mobile-chrome-web-screenshot

Mobile Web - Safari

expensify-mobile-safari-web-screenshot

Desktop
expensify-mac-desktop-paste-without-new-word.mov
iOS

expensify-ios-native-screenshot

Android

expensify-android-native-screenshot

@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2023

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@Victor-Nyagudi
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@Victor-Nyagudi Victor-Nyagudi marked this pull request as ready for review May 1, 2023 19:14
@Victor-Nyagudi Victor-Nyagudi requested a review from a team as a code owner May 1, 2023 19:14
@melvin-bot melvin-bot bot requested review from Beamanator and fedirjh and removed request for a team May 1, 2023 19:14
@MelvinBot
Copy link

@Beamanator @fedirjh One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@fedirjh
Copy link
Contributor

fedirjh commented May 1, 2023

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Screen.Recording.2023-05-01.at.10.07.13.PM.mov
Mobile Web - Chrome

Screenshot_1682977715

Mobile Web - Safari

Simulator Screenshot - iPhone 14 - 2023-05-01 at 22 39 00

Desktop
Screen.Recording.2023-05-01.at.10.08.34.PM.mov
iOS

Simulator Screenshot - iPhone 14 - 2023-05-01 at 22 39 26

Android

Screenshot_1682977641

fedirjh
fedirjh previously approved these changes May 1, 2023
Copy link
Contributor

@fedirjh fedirjh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

cc @Beamanator All yours

Beamanator
Beamanator previously approved these changes May 2, 2023
Copy link
Contributor

@Beamanator Beamanator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💪

Co-authored-by: Alex Beaman <dabeamanator@gmail.com>
@Victor-Nyagudi Victor-Nyagudi dismissed stale reviews from Beamanator and fedirjh via 2652e7d May 2, 2023 15:24
@Beamanator Beamanator merged commit 4d4d484 into Expensify:main May 2, 2023
@OSBotify
Copy link
Contributor

OSBotify commented May 2, 2023

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

OSBotify commented May 3, 2023

🚀 Deployed to staging by https://github.com/Beamanator in version: 1.3.9-12 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@AndrewGable
Copy link
Contributor

Hey all - This caused a deploy blocker here: #18376

I reverted it here: #18380

@Victor-Nyagudi
Copy link
Contributor Author

@AndrewGable I'm currently investigating the unintended behavior.

Thanks.

@fedirjh
Copy link
Contributor

fedirjh commented May 4, 2023

cc @Beamanator , @Victor-Nyagudi

Problem

During my investigation of this regression, I discovered that a top-level (or "parent") div had a user-select: none; style applied to it. When this div is selected, any text within it is removed, and the div itself is removed from the selection, along with its descendant contents.

Screenshot 2023-05-04 at 11 27 17 AM

Solution

We should check for nested elements that have a user-select: text; style inside other elements whose style is user-select: none; and prevent them from being removed from selection

// Query all non selectable element that doesn’t have any child that have a selectable text
div.querySelectorAll('*[style*="user-select: none"]:not(:has(*[style*="user-select: text"]))')
    .forEach(item => item.remove());

@Victor-Nyagudi
Copy link
Contributor Author

I was just about to post my findings as you posted yours, @fedirjh.

Problem

I also discovered there are a couple of other components that have the user-select: none style applied. Some of these are an ancestor with a considerable number of children, grandchildren, etc., so when we remove any div with this style applied, the component and all its descendants are removed.

One of the bigger components being OfflineWithFeedback.

const props = {style: StyleUtils.combineStyles(child.props.style, styles.offlineFeedback.deleted, styles.userSelectNone)};

this.props.isDisabled ? styles.userSelectNone : null,

Solution

I explored two possible solutions with the first being the one I went with, and the second being one that could require a bit more work but is more future-proof, however, I'd require some input on it first.

  • Option 1

From my search using VS Code's search tool, I discovered the only component using accessibilityHints.newMessageLineIndicator is UnreadActionIndicator, and the only component using UnreadActionIndicator is ReportActionItem.

Given only one message can be marked unread at a time and the single use-case scenario mentioned above, I opted to just grab the div with this accessibility label (localized, of course) and removed it from the copied items inside SelectionScraper.

// Get the div housing the UnreadActionIndicator and remove it from copied content
div.querySelector(`[aria-label="${Localize.translateLocal('accessibilityHints.newMessageLineIndicator')}"]`)
    .remove();

Should things change in future and multiple messages can be marked as unread, we can update this to div.querySelectorAll() to cover all those other unread message indicators.

Here are a couple of videos with my changes applied.

Mac Chrome English
expensify-mac-chrome-unread-message-english.mov
Mac Chrome Spanish
expensify-mac-chrome-unread-message-spanish.mov
Mac Safari English
expensify-mac-safari-unread-message-english.mov
Mac Safari Spanish
expensify-mac-safari-unread-message-spanish.mov
Mac Desktop English
expensify-mac-desktop-unread-message-english.mov
Mac Desktop Spanish
expensify-mac-desktop-unread-message-spanish.mov

This is a very specific fix, though, and only covers UnreadMessageIndicator, but given its very limited use, there's a lower risk of regressions occurring.

As you can see, the emojis are now being copied again. In the previous solution in this PR that caused a regression, the emojis weren't being copied, so it looks like we may have been onto something in possibly fixing other issues involving copying emojis or inadvertently copying text.

On the other hand, I don't think it would be a bad idea to focus on one issue at a time, and then propose solutions to the other copying issues once this one is fixed with no regressions.

  • Option 2 (Requires input)

I dabbled with the idea of components that should not be copied receiving a shouldElementBeCopiedToClipboard prop that would determine whether or not the component gets an attribute like data-shouldElementBeCopiedToClipboard="false".

We could then go through all the elements with this attribute set to true like before and remove them, but I felt like this would require a bigger change in terms of adding props to the component in the pages it's been used.

div.querySelectorAll(`div[data-shouldElementBeCopiedToClipboard="${shouldElementBeCopiedToClipboard}"]`)
    .forEach(item => item.remove());

I like @fedirjh proposal though. We could also go with that. Support for :has() has improved a lot, but it still needs to be enabled on Firefox i.e. not supported by default.

cc: @Beamanator

P.S. Notice how in the videos I've shared in this comment how copying the messages from the left side to right doesn't copy the emojis (text cursor is visible) but copying from the right side to left (default cursor) does.

Just some food for thought going forward.

@bernhardoj
Copy link
Contributor

@fedirjh @Victor-Nyagudi
Just sharing my opinion here.

I previously mentioned that this bug is a browser bug here #15194 (comment), but looks like everyone disagree with it (the bug isn't reproducible in Firefox). You can found the Chromium bug report from my comment. At first, I thought it's already fixed on the latest version of Chrome, but turns out it's still reproducible and also the commits getting reverted because of a regression.

I think the commit could be useful especially the test case. If I understand @fedirjh solution correctly, it will select the non selectable text for this case:

<div style="user-select: none">
    SKIP
    <div style="user-select: text">
        KEEP
    </div>
</div>

Result: SKIP KEEP

However, based on the chromium test case, only KEEP text should be copied. Here is one of the test case example on nested user-select
image

I think it would require a lot of changes to cover all cases without any regression. Even the chromium commits getting reverted 🤣. So, if I can suggest, I would go for the solution to only exclude the text on a specific component in the meantime, in this case the new message indicator, while waiting the full fix from Chromium, which I guess will be taking very long, not to mention Safari.

@fedirjh
Copy link
Contributor

fedirjh commented May 8, 2023

Thank you for the thorough investigation, @bernhardoj. Your explanation is very helpful. I suggest that we go with @Victor-Nyagudi's option 1, which will only exclude the text on a specific component, UnreadActionIndicator. We attempted to make a global fix for this issue, but it seems that it is not currently feasible. @Beamanator, what are your thoughts on this? What should be our next steps? Should we go with this option, or should we revisit the main issue and search for another global fix that addresses all cases?

@OSBotify
Copy link
Contributor

OSBotify commented May 9, 2023

🚀 Deployed to production by https://github.com/roryabraham in version: 1.3.12-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@Victor-Nyagudi
Copy link
Contributor Author

I'm a little confused here.

This PR was reverted by @AndrewGable but has been deployed to production.

Is it the reverted PR that's been deployed to production and we're just being notified, or did something happen in between?

@Beamanator
Copy link
Contributor

@Victor-Nyagudi yeah i can see that it's confusing, I looked at the changes made by the revert PR, and they're what's currently in the production branch

@Beamanator
Copy link
Contributor

Thank you for the thorough investigation, @bernhardoj. Your explanation is very helpful. I suggest that we go with @Victor-Nyagudi's option 1, which will only exclude the text on a specific component, UnreadActionIndicator. We attempted to make a global fix for this issue, but it seems that it is not currently feasible. @Beamanator, what are your thoughts on this? What should be our next steps? Should we go with this option, or should we revisit the main issue and search for another global fix that addresses all cases?

@fedirjh I agree with this conclusion 👍

Since @Victor-Nyagudi is the author of this PR (which was reverted), @Victor-Nyagudi can you please make the fix PR & link it to the original issue & mention this one as well?

@Victor-Nyagudi
Copy link
Contributor Author

@Beamanator Got it.

I'll get to work on the PR.

Glad that's cleared up.

@Beamanator
Copy link
Contributor

Thanks @Victor-Nyagudi 👍

@Victor-Nyagudi
Copy link
Contributor Author

PR is ready for review.

Let me know if there's anything else you need me to do.

cc: @fedirjh @Beamanator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants